package com.goomba.delay;

import com.goomba.demo.contants.Commons;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class Consumer {

    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("delay_consumer_group");

        consumer.setNamesrvAddr(Commons.nameSrvAddr);

        consumer.subscribe("delay_topic", "tag1");

        consumer.registerMessageListener((MessageListenerConcurrently) (list, consumeConcurrentlyContext) -> {

            for (MessageExt ext : list) {
                System.out.println(Thread.currentThread().getName() + " 获取的数据是 " + new String(ext.getBody()));

            }

            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        });


        consumer.start();


    }

}
